package com.ruoyi.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.RecordBorcart;
import com.ruoyi.system.mapper.RecordBorcartMapper;
import com.ruoyi.system.service.IRecordBorcartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 借阅车Service业务层处理
 *
 * @author admin
 * @date 2022-03-10
 */
@Service
public class RecordBorcartServiceImpl implements IRecordBorcartService {
    @Autowired
    private RecordBorcartMapper recordBorcartMapper;

    /**
     * 查询借阅车
     *
     * @param cartId 借阅车主键
     * @return 借阅车
     */
    @Override
    public RecordBorcart selectRecordBorcartByCartId(Long cartId) {
        return recordBorcartMapper.selectRecordBorcartByCartId(cartId);
    }

    /**
     * 查询借阅车列表
     *
     * @param recordBorcart 借阅车
     * @return 借阅车
     */
    @Override
    public List<RecordBorcart> selectRecordBorcartList(RecordBorcart recordBorcart) {
        recordBorcart.setUserId(SecurityUtils.getUserId());
        return recordBorcartMapper.selectRecordBorcartList(recordBorcart);
    }

    /**
     * 新增借阅车
     *
     * @param recordBorcart 借阅车
     * @return 结果
     */
    @Override
    public int insertRecordBorcart(RecordBorcart recordBorcart) {
        recordBorcart.setUserId(SecurityUtils.getUserId());
        List<RecordBorcart> cartOldList = this.selectRecordBorcartList(recordBorcart);
        if (cartOldList.size() != 0) {
            throw new ServiceException("禁止重复添加");
        }
        return recordBorcartMapper.insertRecordBorcart(recordBorcart);
    }

    /**
     * 修改借阅车
     *
     * @param recordBorcart 借阅车
     * @return 结果
     */
    @Override
    public int updateRecordBorcart(RecordBorcart recordBorcart) {
        return recordBorcartMapper.updateRecordBorcart(recordBorcart);
    }

    /**
     * 批量删除借阅车
     *
     * @param cartIds 需要删除的借阅车主键
     * @return 结果
     */
    @Override
    public int deleteRecordBorcartByCartIds(Long[] cartIds) {
        return recordBorcartMapper.deleteRecordBorcartByCartIds(cartIds);
    }

    /**
     * 删除借阅车信息
     *
     * @param cartId 借阅车主键
     * @return 结果
     */
    @Override
    public int deleteRecordBorcartByCartId(Long cartId) {
        return recordBorcartMapper.deleteRecordBorcartByCartId(cartId);
    }
}
